package com.yanqu.road.server.gameplayer.module.player;

import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.pb.common.CommonProto;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.base.GeneralModule;
import com.yanqu.road.server.manger.system.PlatformGoodsMgr;
import com.yanqu.road.server.pb.CommonPb;
import com.yanqu.road.server.protocol.Protocol;

import java.util.ArrayList;
import java.util.List;

public class PlatformGoodsModule extends GeneralModule {
    public PlatformGoodsModule(GamePlayer player) {
        super(player);
    }

    @Override
    public boolean loadData() {
        return true;
    }

    @Override
    public boolean afterLoadData() {
        return false;
    }

    @Override
    public boolean saveData() {
        return false;
    }

    @Override
    public void loginSendMsg() {
        syncPlatformData();
    }

    public void syncPlatformData(){
        List<GoodsInfo> goodsInfoList = PlatformGoodsMgr.getGoodsInfoList();
        if(goodsInfoList.size() > 0) {
            CommonProto.GoodsListMsg.Builder listMsg = CommonPb.parseGoodsListMsg(goodsInfoList, player.getLanguage(), new ArrayList<>());
            player.sendPacket(Protocol.U_PLATFORM_GOODS_INFO_SYNC, listMsg);
        }
    }
}
